package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdd.ehe.entity.Role;
import com.zdd.ehe.mapper.RoleMapper;
import com.zdd.ehe.service.IRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-03-13
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Resource
    private RoleMapper roleMapper;
    /**
     * 获取角色权限列表
     *
     * @param role
     * @return
     */
    @Override
    public List<String> getPermissions(String role){
        List<String> permissionList = roleMapper.getPermissionsByRole(role);
        return permissionList;
    }

    /**
     * 分页查询角色列表
     *
     * @param page
     * @return
     */
    @Override
    public Page<Role> getAllRoleByPage(Page<Role> page) {
        Page<Role> pagex = roleMapper.getAllRoleByPage(page);
        return pagex;
    }


    /*
    * 根据 id 查询 role
    * */
    @Override
    public Role selectRoleById(Integer id){
        Role role = roleMapper.selectRoleById(id);
        return role;
    }

    /*
    * 根据id修改角色信息
    * */
    public int updateRoleById(Role role){
        int result = -1;
        try {
            result = roleMapper.updateRoleById(role);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }



    /**
     * 添加角色
     * @param role
     * @return
     */
    public int addRole(Role role){
        int result = -1;
        try {
            result = roleMapper.addRole(role);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


}
